﻿namespace DistrRTgen
{
    using System;
    using System.Configuration;
    using System.Runtime.CompilerServices;
    using System.Xml.Serialization;

    [XmlInclude(typeof(WorkUnit)), XmlRoot("WorkUnit"), SettingsSerializeAs(SettingsSerializeAs.Xml)]
    public class WorkUnit : MarshalByRefObject
    {
        private uint _ChainCount;
        private uint _ChainLength;
        private ulong _ChainStart;
        private string _Charset;
        private bool _Done;
        private string _HashRoutine;
        private uint _Index;
        private bool _InUse;
        private DateTime _LastUploadTry;
        private uint _MaxLetters;
        private uint _MinLetters;
        private uint _PartID;
        private int _PercentUploaded;
        private string _Salt;
        private bool _Uploading;

        public event cuWURemoved WURemoved;

        public WorkUnit()
        {
        }

        public WorkUnit(uint PartID, string HashRoutine, string Charset, uint MinLetters, uint MaxLetters, uint Index, uint ChainLength, uint ChainCount, ulong ChainStart, string Salt)
        {
            this.PartID = PartID;
            this.HashRoutine = HashRoutine;
            this.Charset = Charset;
            this.MinLetters = MinLetters;
            this.MaxLetters = MaxLetters;
            this.Index = Index;
            this.ChainLength = ChainLength;
            this.ChainCount = ChainCount;
            this.ChainStart = ChainStart;
            this.Salt = Salt;
        }

        public void BeginUploading()
        {
            this._Uploading = true;
        }

        public void BeginUse()
        {
            this._InUse = true;
        }

        public void EndUploading()
        {
            this._LastUploadTry = DateTime.Now;
            this._Uploading = false;
        }

        public void StopUse()
        {
            this._InUse = false;
        }

        public void TriggerRemoved()
        {
            if (this.WURemoved != null)
            {
                this.WURemoved();
            }
        }

        public uint ChainCount
        {
            get
            {
                return this._ChainCount;
            }
            set
            {
                this._ChainCount = value;
            }
        }

        public uint ChainLength
        {
            get
            {
                return this._ChainLength;
            }
            set
            {
                this._ChainLength = value;
            }
        }

        public ulong ChainStart
        {
            get
            {
                return this._ChainStart;
            }
            set
            {
                this._ChainStart = value;
            }
        }

        public string Charset
        {
            get
            {
                return this._Charset;
            }
            set
            {
                this._Charset = value;
            }
        }

        public bool Done
        {
            get
            {
                return this._Done;
            }
            set
            {
                this._Done = value;
            }
        }

        public string HashRoutine
        {
            get
            {
                return this._HashRoutine;
            }
            set
            {
                this._HashRoutine = value;
            }
        }

        public uint Index
        {
            get
            {
                return this._Index;
            }
            set
            {
                this._Index = value;
            }
        }

        [XmlIgnore]
        public bool InUse
        {
            get
            {
                return this._InUse;
            }
        }

        public DateTime LastUploadTry
        {
            get
            {
                return this._LastUploadTry;
            }
        }

        public uint MaxLetters
        {
            get
            {
                return this._MaxLetters;
            }
            set
            {
                this._MaxLetters = value;
            }
        }

        public uint MinLetters
        {
            get
            {
                return this._MinLetters;
            }
            set
            {
                this._MinLetters = value;
            }
        }

        public uint PartID
        {
            get
            {
                return this._PartID;
            }
            set
            {
                this._PartID = value;
            }
        }

        public int PercentUploaded
        {
            get
            {
                return this._PercentUploaded;
            }
            set
            {
                this._PercentUploaded = value;
            }
        }

        public string Salt
        {
            get
            {
                return this._Salt;
            }
            set
            {
                this._Salt = value;
            }
        }

        public bool Uploading
        {
            get
            {
                return this._Uploading;
            }
        }

        public delegate void cuWURemoved();
    }
}

